<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>机构配费月报表</title>
</head>
<body>
    <div ng-app="OrganizationSalaryApp" ng-controller="OrganizationSalaryCtrl">
        <div class="row">
            <ui-container url="report/organizationsalary/list" key="report-organizationsalary-list-00">
                <ui-search-form>
                    <div class="col-md-4">
                        <button class="btn btn-sm btn-success" data-toggle="modal" data-target="#myModal">选择机构</button>
                        <label id="showlabel"></label>
                        <input type="hidden" readonly="readonly" name="organizationCode"/>
                    </div>
                </ui-search-form>
                <ui-table-tool>
                    <a  class="btn btn-sm btn-primary" ng-click="exportDatas()" target="_blank" >导出</a>
                </ui-table-tool>
                <ui-table>

                </ui-table>
                <table-page/>
            </ui-container>
        </div>
    </div>
    <!-- 模态框（Modal） -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        &times;
                    </button>
                    <h5 class="modal-title" id="myModalLabel">
                        选择组织机构
                    </h5>
                </div>
                <div class="modal-body" style="height: 60px;">

                    <div class="col-md-6">
                         <input type="text" placeholder="输入组织机构名称 按回车查询" id="orgName" class="form-control"  name />
                    </div>

                        <div id="showSelect" style="display:none">

                            <div class="col-md-6">
                                <select class="form-control">
                                    <option>请选择</option>
                                </select>
                            </div>

                        </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                    </button>
                    <button type="button" id="closeModal" class="btn btn-primary">
                        提交更改
                    </button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>
<script>
    $("#closeModal").bind('click',function () {
        var option=$("#showSelect").find("select")[0].selectedOptions[0];
        $("#showlabel").html('').html(!option.value?'':"已选择<span style='color:green;'>"+option.text+'</span>');
        $("input[name='organizationCode']").val(option.value);
        $("#myModal").modal('hide');
        $("#showSelect").hide();
    });
    $("#orgName").bind("keyup",function (event) {
        if(event.key==="Enter"){
            $("#showSelect").hide();
            $.ajax({
                url:'system/organization/listbyname',
                type:'post',
                data:{key:event.currentTarget.value},
                success:function (result) {
                    if(result.code=="0000"){
                        var datas=result.data||[];
                        var str="<option value=''>请选择</option>";
                        for (var i in datas){
                            str+="<option value='"+datas[i].code+"'>"+datas[i].name+"</option>";
                        }
                        $("#showSelect").find("select").html('').html($(str));
                        $("#showSelect").show();
                    }
                }
            })
        }
    })
    angular.module('OrganizationSalaryApp',['ui.table']);
    angular.module('OrganizationSalaryApp').controller('OrganizationSalaryCtrl', function($scope){
        $scope.exportDatas=function(){
            var uiContainerCtrl=$scope['report-organizationsalary-list-00'];
            //如果下面的表格没有数据（可能是没有搜索可能是没有结果）就判断不能导出
            var tableData=uiContainerCtrl._dataList;
            if (!tableData || tableData.length <= 0) {
                toastr.error('表格数据为空，不能导出');
                return;
            }
            var paramData=uiContainerCtrl._getFormParams();


            var params = {
                url: 'report/organizationsalary/export',
                type: "POST"
            };
            var exportForm = $("<form>");
            for (let i in paramData) {
                if(paramData[i]!=undefined&&paramData[i]!=null&&paramData[i]!=''){
                    $("<input type='hidden' name='" + i + "' value='" + paramData[i] + "'/>").appendTo(exportForm);
                }
            }
            $(exportForm).css("display", "none");
            $(exportForm).attr('target', 'targetFrame');
            $(exportForm).attr('method', params.type);
            $(exportForm).attr('action', params.url);
            exportForm = exportForm.appendTo($("body"));
            exportForm.submit();
            exportForm.remove();
        }
        //每一列的操作按钮
        $scope._columns=[
            {name:'organizationCode',head:'组织机构编号'},
            {name:'organizationName',head:'组织机构名称'},
            {name:'month',head:'月份'},
            {name:'majorSum',head:'首件单量'},
            {name:'minorSum',head:'拖件单量'},
            {name:'majorFee',head:'首件配费'},
            {name:'minorFee',head:'拖件配费'},
            {name:'totalFee',head:'总配费'}
        ];
    });
</script>
</body>
</html>
